<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Dubbo</title>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/public.css">
    <script src="js/function/sosowx.js?v=0.2"></script>
    <script type="text/javascript">
        var dataId;
        var source;
        /**
         * 初始数据源
         */
        function init() {
            dataId = GetQueryString("id");
            getSourceList();
        }
        /**
         * 初始化数据源字段
         */
        function initSColumnList(sourceId) {
            source = sourceId;
            getSColumnList();
        }
        /**
         * 获取数据源列表
         */
        function getSourceList() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getSourceList/"+dataId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#sourceList").html("<thead> <td>数据源名称</td> <td>表名</td> <td>主键字段</td> <td>sql语句</td> <td>排序子句</td> <td>操作</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].source_name + "</td>"
                                + "<td>" + data[i].source_table + "</td>"
                                + "<td>" + data[i].source_pk + "</td>"
                                + "<td>" + data[i].source_sql + "</td>"
                                + "<td>" + data[i].source_order + "</td>"
                                + "<td><a href=\"#\" onclick=\"initSColumnList("+data[i].source_id+")\">维护数据源字段</a></td>";
                        table += "</tr>";
                        $("#sourceList").append(table);
                    }
                }
            });
        }

        /**
         * 获取数据源字段
         */
        function getSColumnList() {
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getSColumnList/"+source,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#sColumnList").html(" <thead> <td>数据源名称</td> <td>表名</td> <td>主键字段</td> <td>sql语句</td> <td>字段长度</td> <td>主键</td> <td>外键</td> <td>排序子句</td> </thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].colum_name + "</td>"
                                + "<td>" + data[i].colum_table + "</td>"
                                + "<td>" + data[i].colum_type + "</td>"
                                + "<td>" + data[i].colum_mean + "</td>"
                                + "<td>" + data[i].colum_length + "</td>"
                                + "<td>" + data[i].colum_pk + "</td>"
                                + "<td>" + data[i].colum_fk + "</td>"
                                + "<td>" + data[i].colum_order + "</td>"
                        table += "</tr>";
                        $("#sColumnList").append(table);
                    }
                }
            });
        }

        /**
         * 保存数据源
         */
        function saveSource() {
            var datas = {
                source_name: $("#sname").val(),
                source_table: $("#stable").val(),
                source_pk: $("#spk").val(),
                source_sql: $("#ssql").val(),
                source_order: $("#sorder").val(),
                source_type: $("#stype").val(),
                data_id: dataId
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_SOURCE,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getSourceList();
                }
            });
        }
        /**
         * 保存数据源字段
         */
        function savesColumn() {
            var datas = {
                colum_name: $("#cname").val(),
                colum_table: $("#ctable").val(),
                colum_type: $("#ctype").val(),
                colum_mean: $("#cmean").val(),
                colum_length: $("#clength").val(),
                colum_pk: $("#cpk").val(),
                colum_fk: $("#cfk").val(),
                source_id: source,
                source_orgpk: $("#orgpk").val(),
                source_fkc: $("#fkc").val(),
                source_fkkey: $("#fkkey").val(),
                source_fkval: $("#fkval").val(),
                source_asbane: $("#asbane").val(),
            }
            $.ajax({
                type: "POST",
                url: "/metadataNew/insert/"+Table.META_SOURCE_COLUMN,
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    getSColumnList();
                }
            });
        }

    </script>
</head>
<body onload="init();">
<div style="width: auto; float: left">
    <h6>维护数据源</h6>
    名称：<input type="text" id="sname">表名：<input type="text" id="stable">

    <p/>
    主键字段：<input type="text" id="spk">SQL：<input type="text" id="ssql">
    排序字句：<input type="text" id="sorder">类型：<input type="text" id="stype">

    <p/>
    <input type="button" value="新增数据源" onclick="saveSource()">

    <p/>
    <table id="sourceList">
        <thead>
        <td>数据源名称</td>
        <td>表名</td>
        <td>主键字段</td>
        <td>sql语句</td>
        <td>排序子句</td>
        <td>操作</td>
        </thead>
    </table>
</div>
<div style="width: auto; float: left">
    <h6>维护数据源字段</h6>
    字段名：<input type="text" id="cname">表名：<input type="text" id="ctable">

    <p/>
    类型：<input type="text" id="ctype">含义：<input type="text" id="cmean">

    <p/>
    长度：<input type="text" id="clength">数据源主键：<input type="text" id="orgpk">

    <p/>
    主键：<input type="text" id="cpk">外键：<input type="text" id="cfk">
    <p/>
    外键字段：<input type="text" id="fkc">关联数据建：<input type="text" id="fkkey">
    <p/>
    关联数据值：<input type="text" id="fkval">关联数据别名：<input type="text" id="asname">
    <p/>
    <input type="button" value="新增字段" onclick="savesColumn()">
    <p/>
    <table id="sColumnList">
        <thead>
        <td>数据源名称</td>
        <td>表名</td>
        <td>主键字段</td>
        <td>sql语句</td>
        <td>字段长度</td>
        <td>主键</td>
        <td>外键</td>
        <td>排序子句</td>
        </thead>
    </table>
</div>
</body>
</html>